import { NextRequest } from "next/server";
import { headers, cookies } from "next/headers";

export async function GET(request: NextRequest) {
    // 方法一 new Headers(request.headers)
    // 获取请求头
    const requestHeaders = new Headers(request.headers);
    // 打印出请求头中的Authorization的值
    console.log("Authorization Value:", requestHeaders.get("Authorization"));

    // 方法二 headers()
    const headersList = await headers();
    console.log("Authorization value: ", headersList.get("Authorization"));

    // 方法一 获取 cookies
    const theme = request.cookies.get("theme");
    console.log(theme);

    // 方法二 获取和设置cookies
    const cookieStore = await cookies();
    cookieStore.set("result", "2025");
    console.log(cookieStore.get("result"));

    return new Response("<h1>profile api route</h1>", {
        headers: {
            "Content-Type": "text/html",
            // 方法一设置cookies
            // "Set-Cookie": "theme=dark"
        }
    });
} 